package util

import (
	"github.com/json-iterator/go"
	"io"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

func ToJson(v interface{}) ([]byte, error) {
	return json.Marshal(v)
}

func ToJsonString(v interface{}) (string, error) {
	return json.MarshalToString(v)
}

func WriteJson(writer io.Writer, v interface{}) (error) {
	return json.NewEncoder(writer).Encode(v)
}

func FromJson(data []byte, v interface{}) (er error) {
	return json.Unmarshal(data, v)
}

func FromJsonString(data string, v interface{}) (er error) {
	return json.UnmarshalFromString(data, v)
}

func FromJsonReader(reader io.Reader, v interface{}) (er error) {
	return json.NewDecoder(reader).Decode(v)
}
